package com.taojie.graduation.controller;

import com.taojie.graduation.domain.Store;
import com.taojie.graduation.service.api.StoreService;
import com.taojie.graduation.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@CrossOrigin
@Api(tags = {"商铺接口"})
@RequestMapping("store")
public class StoreController {
    @Resource
    private StoreService storeService;

    @ApiOperation("分页查询")
    @GetMapping("{page}/{size}")
    public Result page(@PathVariable("page") int page, @PathVariable("size") int size, @RequestParam(value = "query", required = false) String query){
        return storeService.findStorePage(page, size, query);
    }

    @ApiOperation("根据id查询商铺")
    @GetMapping("{id}")
    public Result findById(@PathVariable("id") Integer id){
        return storeService.findStoreById(id);
    }

    @ApiOperation("根据id更新商铺")
    @PutMapping("{id}")
    public Result updateById(@PathVariable("id") Integer id,@RequestBody Store store){
        store.setId(id);
        return storeService.updateById(store);
    }

    @ApiOperation("根据id删除商铺")
    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable("id")Integer id){
        return storeService.deleteById(id);
    }

    @ApiOperation("添加商铺")
    @PostMapping
    public Result addr(@RequestBody Store store) {
        return storeService.add(store);
    }
    
}
